// 动态规划方式
const maxSubArray = (arr) => {
    if (!(arr && arr.length > 0)) {
        return;
    }
    let pre = 0;
    let maxChild = arr[0];
    arr.forEach(item => {
        pre = Math.max(pre + item, item);
        maxChild = Math.max(maxChild, pre);
    })
    return maxChild;
}

const arr = [12,3,123,12,3,-1,-2,-3];
console.log('结果 => ', maxSubArray(arr))